
#pragma once

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include "BloomFilter.h"
#include "Index.h"

using namespace std;

class FilterMap
{
public:
	FilterMap(int bitArrayLength, bool onlyAccount, const string& fileName);
	~FilterMap(void);
	int Search(const string& key);
	int SearchWithList(const string& fileName);
	void RebuildBloomFilterFromPath(const string& path, int start, int end) ;
	bool SaveToFile(const string& fileName);
private:
	void ClearData(void);
	void SaveData(void);
	bool BuildBloomFilterFile(const string& fileName);
	BloomFilter* GetBloomFilter(const string& index);
	bool LoadFromFile(const string& fileName);
	bool ParseLine(const string& line);
	bool Find(const string& key, vector<string>& result);
	int ReadContent(const string& key, const string& fileName);
	Index *GetCache(const string& fileName);
	int ReadContentFromCache(const string& key, const string& fileName);
private:
	int bitArrayLength;
	bool updated;
	bool onlyAccount;
	map<string, BloomFilter*> filtersMap;
	map<string, Index* > indicesCache;
	string filterFileName;
	string currentPath;
	
};

